package com.novunda.platform.entities;


import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.google.common.collect.Lists;
import com.novunda.platform.entities.base.DataEntity;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.*;
import org.hibernate.validator.constraints.Length;

import javax.persistence.CascadeType;
import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import java.util.List;

/**
 * 采集统计Entity
 *
 * @author Lizy
 * @version 2016-09-8
 */
@Entity
@Table(name = "conf_statistics")
@DynamicInsert
@DynamicUpdate
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Statistics extends DataEntity {
    /**
     * id
     */
    private Long id;
    /**
     * 活跃值
     */
    private int livelyTime;
    /**
     * 审计记录条数
     */
    private long recordNumber;
    /**
     * 审计记录状态：0为记录，1为不记录
     */
    private int recordStatus;
    /**
     * 审计记录告警值
     */
    private long recordAlarm;
    /**
     * 区间时间
     */
    private List<StatisticsTime> statisticsTimes = Lists.newArrayList();

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column(name = "lively_time")
    public int getLivelyTime() {
        return livelyTime;
    }

    public void setLivelyTime(int livelyTime) {
        this.livelyTime = livelyTime;
    }

    @Column(name = "record_number")
    public long getRecordNumber() {
        return recordNumber;
    }

    public void setRecordNumber(long recordNumber) {
        this.recordNumber = recordNumber;
    }

    @Column(name = "record_alarm")
    public long getRecordAlarm() {
        return recordAlarm;
    }

    public void setRecordAlarm(long recordAlarm) {
        this.recordAlarm = recordAlarm;
    }

    @Column(name = "record_status")
    public int getRecordStatus() {
        return recordStatus;
    }

    public void setRecordStatus(int recordStatus) {
        this.recordStatus = recordStatus;
    }

    @OneToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE}, fetch = FetchType.EAGER, mappedBy = "statistics")
    @Where(clause = "del_flag='" + DEL_FLAG_NORMAL + "'")
    @OrderBy("id")
    @NotFound(action = NotFoundAction.IGNORE)
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    public List<StatisticsTime> getStatisticsTimes() {
        return statisticsTimes;
    }

    public void setStatisticsTimes(List<StatisticsTime> statisticsTimes) {
        this.statisticsTimes = statisticsTimes;
    }
}
